package com.op.teachingliteapp.util.asynctask;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;

public class DialogHelper {

	private ProgressDialog prDialog;
	private final AsyncTask<?, ?, ?> task;

	public DialogHelper(Context context, AsyncTask<?, ?, ?> task) {
		this.task = task;
		prDialog = new ProgressDialog(context);
		prDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		prDialog.setMessage("Loading...");
		prDialog.setCancelable(true);
		prDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
			@Override
			public void onDismiss(DialogInterface paramDialogInterface) {
				DialogHelper.this.task.cancel(false);
				prDialog.cancel();
			}
		});
	}

	public void showProgressDialog() {
		prDialog.show();
	}

	public void dismissProgressDialog() {
		prDialog.cancel();
	}
}
